package com.hopu.v1.controller.admin.subject;

import com.hopu.v1.pojo.common.R;
import com.hopu.v1.pojo.course.Course;
import com.hopu.v1.service.admin.subject.ACourseService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController()
@RequestMapping("api/v1/admin/course")
public class   ACourseController {

    @Resource
    private ACourseService ACourseService;;

    /**
     * 获取课程信息
     * @return
     */
    @GetMapping
    public R getCourseList(Integer subjectId) {
        System.out.println(subjectId);
        return R.ok(ACourseService.getCourseList(subjectId));
    }


    /**
     * 获取所有课城数据
     */
    @GetMapping("all")
    public R getAllCourseList(Integer pid) {return R.ok(ACourseService.selectChildCourse(pid));}

    /**
     * 根据id修改课程名字
     * @param courseId
     * @param courseName
     * @return
     */
    @PutMapping
    public R updateCourseNameById(@RequestParam Integer courseId,@RequestParam String courseName) {
        Course course = new Course();
        course.setId(Long.valueOf(courseId));
        course.setCourseName(courseName);
        ACourseService.updateById(course);
        return R.ok("修改成功");
    }


    /**
     * 根据id删除课程
     * @param courseId
     * @return
     */
    @DeleteMapping
    public R deleteCourseById(@RequestParam Integer courseId){
        System.out.println(courseId);
        ACourseService.removeById(courseId);
        return R.ok("删除成功");
    }

    /**
     * 根据课程id修改课程内容
     * @param course
     * @return
     */
    @PutMapping("courseContent")
    public R updateContentById(@RequestBody Course course){
        ACourseService.updateById(course);
        return R.ok("保存成功");
    }


    /**
     * 添加课件 （添加名）
     * @param course
     * @return
     */
    @PostMapping
    public R insertCourseName(@RequestBody Course course){
        ACourseService.save(course);
        return R.ok("添加成功");
    }

    /**
     * 查询班级的进度
     * @param classId
     * @param pid
     * @param status
     * @return
     */
    @GetMapping("selectAllCourseByClassId")
    public R selectAllCourseByClassId(Integer classId, Integer pid, Integer status,Integer subjectId) {
        return R.ok(ACourseService.selectAllCourseByClassId(classId,pid,status,subjectId));
    }

    /**
     * 查询班级的进度
     * @param classId
     * @return
     */
    @GetMapping("selectCourseByClassId")
    public R selectCourseByClassId(Integer classId) {
        return R.ok(ACourseService.selectCourseByClassId(classId));
    }
}
